import run_request_service as rrs
import pymysql
mainDb = pymysql.connect(host='localhost', port=23306, user='root', password='Pr0dkcd_', db="kcdoc")
db_cursor = mainDb.cursor()

if __name__ == '__main__':
    #can.jin
    # yanji.wang
    # sql = """
    #  SELECT
    #  task.ID_ taskId,
    #              ari.USER_ID_ AS oldUser,
    # 						  'dongan.dai' AS newUser
    # FROM
    # 	kc_product_prepare t
    # 	LEFT JOIN kc_process_timeout time ON t.id = time.source_id
    # 	LEFT JOIN act_ru_task task ON time.instance_id = task.PROC_INST_ID_
    #   LEFT JOIN act_ru_identitylink ari ON task.ID_ = ari.TASK_ID_
    # WHERE
    # 	t.form_num in (
    # 	'FT24-00317','FT24-00732','FT24-00733','FT24-00734','FT24-00735','FT24-00802','FT24-00803','FT24-00804','FT24-00805','FT24-00806','FT24-00807','FT24-00808','FT24-00809','FT24-00810','FT24-00811','FT24-00812','FT24-00813','FT24-00814','FT24-00815','FT24-00816','FT24-00817','FT24-00317','FT24-00732','FT24-00733','FT24-00734','FT24-00735','FT24-00802','FT24-00803','FT24-00804','FT24-00805','FT24-00806','FT24-00807','FT24-00808','FT24-00809','FT24-00810','FT24-00811','FT24-00812','FT24-00813','FT24-00814','FT24-00815','FT24-00816','FT24-00817','FT24-00317','FT24-00732','FT24-00733','FT24-00734','FT24-00735','FT24-00802','FT24-00803','FT24-00804','FT24-00805','FT24-00806','FT24-00807','FT24-00808','FT24-00809','FT24-00810','FT24-00811','FT24-00812','FT24-00813','FT24-00814','FT24-00815','FT24-00816','FT24-00817','FT24-00317','FT24-00732','FT24-00733','FT24-00734','FT24-00735','FT24-00802','FT24-00803','FT24-00804','FT24-00805','FT24-00806','FT24-00807','FT24-00808','FT24-00809','FT24-00810','FT24-00811','FT24-00812','FT24-00813','FT24-00814','FT24-00815','FT24-00816','FT24-00817','FT24-00317','FT24-00732','FT24-00733','FT24-00734','FT24-00735','FT24-00802','FT24-00803','FT24-00804','FT24-00805','FT24-00806','FT24-00807','FT24-00808','FT24-00809','FT24-00810','FT24-00811','FT24-00812','FT24-00813','FT24-00814','FT24-00815','FT24-00816','FT24-00817','FT24-00317','FT24-00732','FT24-00733','FT24-00734','FT24-00735','FT24-00802','FT24-00803','FT24-00804','FT24-00805','FT24-00806','FT24-00807','FT24-00808','FT24-00809','FT24-00810','FT24-00811','FT24-00812','FT24-00813','FT24-00814','FT24-00815','FT24-00816','FT24-00817'
    # 	)
    # 	and time.source_type = 3
    # 	and task.ID_ is not null
    #   """
    # sql ="""
    #     SELECT
    #         DISTINCT
    #         task.ID_ taskId,
    #         ari.USER_ID_ as oldUser,
    #         'wen2.zhou' as newUser
    #     FROM
    #         kc_process_timeout time
    #         LEFT JOIN act_ru_task task ON time.instance_id = task.PROC_INST_ID_
    #         LEFT JOIN act_ru_identitylink ari ON task.ID_ = ari.TASK_ID_
    #     WHERE ari.USER_ID_ in ('yuzhu.hu')
	# 			and time.source_type  = 1
	# 	union all
	# 	   SELECT
    #             DISTINCT
    #             task.ID_ taskId,
    #             ari.USER_ID_ as oldUser,
    #             'yongkang.zhou' as newUser
    #         FROM
    #             kc_process_timeout time
    #             LEFT JOIN act_ru_task task ON time.instance_id = task.PROC_INST_ID_
    #             LEFT JOIN act_ru_identitylink ari ON task.ID_ = ari.TASK_ID_
    #         WHERE ari.USER_ID_ in ('wansen.xu')
    # 				and time.source_type  = 1
    # 			union all
    # 		SELECT
    #             DISTINCT
    #             task.ID_ taskId,
    #             ari.USER_ID_ as oldUser,
    #             'yongkang.zhou' as newUser
    #         FROM
    #             kc_process_timeout time
    #             LEFT JOIN act_ru_task task ON time.instance_id = task.PROC_INST_ID_
    #             LEFT JOIN act_ru_identitylink ari ON task.ID_ = ari.TASK_ID_
    #         WHERE ari.USER_ID_ in ('xianglin.feng')
    # 				and time.source_type  = 1
    #      """
    # sql = """
    #       SELECT
    #         task.ID_ taskId,
    #         su1.user_name oldUser,
    #         su2.user_name newUser
    #     FROM
    #         kc_process_timeout time
    #         LEFT JOIN act_ru_task task ON time.instance_id = task.PROC_INST_ID_
    #         LEFT JOIN act_ru_identitylink ari ON task.ID_ = ari.TASK_ID_
    #         INNER JOIN kc_product_prepare kpp ON time.source_id = kpp.id
    #         LEFT JOIN sys_user su1 on su1.user_no = time.principal
    #         LEFT JOIN sys_user su2 on su2.user_no =  kpp.pmc_user
    #         WHERE
    #         time.source_type = 3
    #         AND time.STATUS = 1
    #         AND ari.ID_ IS NOT NULL
    #         AND time.principal <> kpp.pmc_user
    #         AND task.NAME_ = '超时处理'
    #         AND kpp.STATUS = 1;
    #       """

    sql ="""
      SELECT DISTINCT
	task.ID_,
	'liangwei.long' oldUser,
	'dongan.dai' newUser
	
FROM
	kc_foreign_send_apply app
	LEFT JOIN act_ru_task task ON app.instance_id = task.PROC_INST_ID_ 
	LEFT JOIN ACT_RU_IDENTITYLINK ari on  ari.TASK_ID_ = task.ID_
WHERE
	app.plan_id IN (
	SELECT
		id 
	FROM
		kc_production_plan 
	WHERE
		production_code IN (
			'SD24-11614',
			'SD24-11615',
			'SD24-11616',
			'SD24-11617',
			'SD24-11618',
			'SD24-11619',
			'SD24-11620',
			'SD24-11621',
			'SD24-11622',
			'SD24-11623',
			'SD24-11624',
			'SD24-11625',
			'SD24-11626',
			'SD24-11627',
			'SD24-11628',
			'SD24-28131',
			'SD24-28132',
			'SD24-28133',
			'SD24-28134',
			'SD24-28135',
			'SD24-11754',
			'SD24-11755',
			'SD24-11756',
			'SD24-11744',
			'SD24-11748',
			'SD24-11749',
			'SD24-11750',
			'SD24-11751',
			'SD24-11752',
			'SD24-11753',
			'SD24-28499',
			'SD24-28500',
			'SD24-28501',
			'SD24-28502',
			'SD24-28503',
			'SD24-28504',
			'SD24-28505',
			'SD24-28506',
			'SD24-28507',
			'SD24-28508',
			'SD24-28509',
			'SD24-28510',
			'SD24-28511',
			'SD24-28512',
			'SD24-28513',
			'SD24-28514',
			'SD24-28515 ' 
		) 
	)
    
    """
    rrs.login('712017165048788d32c953896cc7ce4a')
    db_cursor.execute(sql)
    fetchall = db_cursor.fetchall()
    for e in fetchall:
        rrs.user_to_task(e[0],e[1] ,e[2])